package com.wyp.microservice.t.rest.sys;
import java.util.Date;
import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wyp.microservice.t.model.Blog;
import com.wyp.microservice.t.service.BlogService;

/**
 * @Description: 接口
 * @Author:  wyp
 * @Date: 2020-11-15 16:14:12
 * @Copyright: Fujian Linewell Software Co., Ltd. All rights reserved.
 */
@Api(value = "/api/sys/t/blog", description = "相关接口", tags = "管理")
@RestController
@RequestMapping("/api/sys/t/blog")
public class BlogResource {

	@Autowired
	private BlogService blogService;


    @GetMapping("getBlogPageList")
    @ApiOperation("获取分页数据")
    @ApiImplicitParams(value = {
                    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "title", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "content", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "firstPicture", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "flag", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "views", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "appreciation", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "notice", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "shareStatement", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "carousel", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "comment", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "published", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "recommend", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "headline", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "createTimeBegin", value = "（起）", paramType = "query"),
                    @ApiImplicitParam(name = "createTimeEnd", value = "（止）", paramType = "query"),
                    @ApiImplicitParam(name = "updateTimeBegin", value = "（起）", paramType = "query"),
                    @ApiImplicitParam(name = "updateTimeEnd", value = "（止）", paramType = "query"),
                    @ApiImplicitParam(name = "typeId", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "userId", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "description", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "tagIds", value = "", paramType = "query"),
                    @ApiImplicitParam(name = "limit", value = "数量", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "offset", value = "偏移量", dataType = "int", paramType = "query", required = true)
    })
    public PageInfo<Blog> getBlogPageList(Long id, String title, String content, String firstPicture, Short flag, Integer views, Short appreciation, Short notice, Short shareStatement, Short carousel, Short comment, Short published, Short recommend, Short headline, Date createTimeBegin, Date createTimeEnd, Date updateTimeBegin, Date updateTimeEnd, Long typeId, Long userId, String description, String tagIds, int offset, int limit) {
        PageHelper.offsetPage(offset, limit);
        return new PageInfo<>(blogService.getBlogList(id, title, content, firstPicture, flag, views, appreciation, notice, shareStatement, carousel, comment, published, recommend, headline, createTimeBegin, createTimeEnd, updateTimeBegin, updateTimeEnd, typeId, userId, description, tagIds));
    }

    @PostMapping("deleteBlog")
    @ApiOperation("删除")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "ids[]", value = "ID列表", dataType = "string", paramType = "form", required = true)
    })
    public void deleteBlog(@RequestParam("ids[]") List<Long> ids) {
        blogService.deleteBlog(ids);
    }

    @GetMapping("getBlog")
    @ApiOperation("获取详情")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "blogId", value = "ID", dataType = "string", paramType = "query")
    )
    public Blog getBlog(Long blogId) {
        return blogService.getBlog(blogId);
    }


    @PostMapping("addBlog")
    @ApiOperation("创建")
    public void addBlog(@RequestBody Blog blog) {
        blogService.addBlog(blog);
    }

    @PostMapping("updateBlog")
    @ApiOperation("更新")
    public void updateBlog(@RequestBody Blog blog) {
        blogService.updateBlog(blog);
    }

}
